Adopt pure entity trees with typed relations#23
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #23 +/- ##
============================================
- Coverage 98.45% 97.67% -0.79%
- Complexity 204 256 +52
============================================
Files 16 16
Lines 453 516 +63
============================================
+ Hits 446 504 +58
- Misses 7 12 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the entity mapping layer to rely on typed properties and reflection for relation detection, while also introducing Style-driven conversion between entity property names and DB column names (camelCase ↔ snake_case) and adding type coercion when hydrating entities.
Changes:
- Update
EntityFactoryto detect relations via type-hint reflection, applystyledProperty()inset()/get(), and add typed coercion for scalar/union/nullability cases. - Update
Standardstyle to convert property names between camelCase and snake_case; updateNorthWindto preserve PascalCase properties. - Migrate test entities/stubs and style integration tests to typed IDs and typed object relations (no
_idscalar relation fields).
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Styles/Sakila/SakilaIntegrationTest.php | Adjust new-entity PK assertion to reflect typed PK property naming. |
| tests/Styles/Sakila/PostCategory.php | Convert join entity fields to typed PK + typed relations. |
| tests/Styles/Sakila/Post.php | Convert entity PK and relation to typed properties. |
| tests/Styles/Sakila/Comment.php | Convert entity PK and relation to typed properties. |
| tests/Styles/Sakila/Category.php | Convert entity PK to typed property. |
| tests/Styles/Sakila/Author.php | Convert entity PK to typed property. |
| tests/Styles/Plural/PostCategory.php | Convert join entity fields to typed PK + typed relations. |
| tests/Styles/Plural/Post.php | Convert entity PK and relation to typed properties. |
| tests/Styles/Plural/PluralIntegrationTest.php | Adjust new-entity PK assertion for typed PK. |
| tests/Styles/Plural/Comment.php | Convert entity PK and relation to typed properties. |
| tests/Styles/Plural/Category.php | Convert entity PK and add typed relation property. |
| tests/Styles/Plural/Author.php | Convert entity PK to typed property. |
| tests/Styles/NorthWind/Posts.php | Convert entity PK and relation to typed properties (PascalCase). |
| tests/Styles/NorthWind/PostCategories.php | Convert join entity fields to typed PK + typed relations (PascalCase). |
| tests/Styles/NorthWind/NorthWindIntegrationTest.php | Adjust new-entity PK assertion for typed PK. |
| tests/Styles/NorthWind/Comments.php | Convert entity PK and relation to typed properties (PascalCase). |
| tests/Styles/NorthWind/Categories.php | Convert entity PK to typed property (PascalCase). |
| tests/Styles/NorthWind/Authors.php | Convert entity PK to typed property (PascalCase). |
| tests/Styles/CakePHP/PostCategory.php | Convert join entity fields to typed PK + typed relations. |
| tests/Styles/CakePHP/Post.php | Convert entity PK and relation to typed properties. |
| tests/Styles/CakePHP/Comment.php | Convert entity PK and relation to typed properties. |
| tests/Styles/CakePHP/Category.php | Convert entity PK and replace scalar FK with typed relation. |
| tests/Styles/CakePHP/CakePHPIntegrationTest.php | Adjust new-entity PK assertion for typed PK. |
| tests/Styles/CakePHP/Author.php | Convert entity PK to typed property. |
| tests/Stubs/TypeCoercionEntity.php | Add a new stub entity for coercion/union/nullability tests. |
| tests/Stubs/Post.php | Convert stub PK + relation to typed properties. |
| tests/Stubs/Issue.php | Convert stub PK to typed property. |
| tests/Stubs/Foo.php | Convert stub PK and tighten text type to `string |
| tests/Stubs/Comment.php | Convert stub PK + relation to typed properties. |
| tests/Stubs/Category.php | Convert stub PK and replace scalar FK with typed relation. |
| tests/Stubs/Bug.php | Convert stub PK to typed property. |
| tests/Stubs/Author.php | Convert stub PK to typed property. |
| tests/EntityFactoryTest.php | Update FK extraction tests for typed relations; add new tests for uninitialized relations and coercion behavior. |
| tests/AbstractMapperTest.php | Remove identity-map test that relied on non-scalar PK assignment now prevented by typed PKs. |
| src/Styles/Standard.php | Implement camelCase↔snake_case conversion for property naming. |
| src/Styles/NorthWind.php | Override property naming conversion to preserve PascalCase. |
| src/EntityFactory.php | Add typed-relation detection via reflection; apply styled property lookup in set/get; add coercion helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7bca9ae to
78ff7d8
Compare
EntityFactory now detects relation properties via type-hint reflection instead of naming conventions, and converts between camelCase entity properties and snake_case DB columns through the Style subsystem. - extractColumns() uses detectRelationProperties() to identify relations by their non-builtin type hints, replacing convention-based isRelationProperty() - set()/get() apply styledProperty() for DB-to-entity name conversion - Type coercion in set() handles numeric strings, union types, and nullability - Standard style styledProperty/realProperty now perform camelCase↔snake_case - NorthWind overrides both to preserve PascalCase as-is - All test stubs use typed properties: int $id (uninitialized), typed object relations (Author $author), no mixed or _id scalars
EntityFactory now detects relation properties via type-hint reflection instead of naming conventions, and converts between camelCase entity properties and snake_case DB columns through the Style subsystem.